$(function () {
    fy(1, 3);
})

function tb() {
    $(".table").append("  <tr>\n" +
        "                <th width=\"100\" style=\"text-align:left; padding-left:20px;\">ID</th>\n" +
        "                <th width=\"10%\">姓名</th>\n" +
        "                <th>头像</th>\n" +
        "                <th>性别</th>\n" +
        "                <th>邮箱</th>\n" +
        "                <th>手机号</th>\n" +
        "                <th width=\"310\">操作</th>\n" +
        "            </tr>")
}

function fy(pageNum, pageSize) {
    $.post("/beyond/selectUser", {"pageNum": pageNum, "pageSize": pageSize}, function (data) {
        $.each(data.list, function (i, cha) {
            var sex = cha.gender == 1 ? "女" : "男";
            $(".table").append("<tr>\n" +
                "                      <td style=\"text-align:left; padding-left:20px;\"><input type=\"checkbox\" name=\"id[]\" value=\"\" />\n" +
                "                       " + (i + 1) + "</td>\n" +
                "                      <td>" + cha.name + "</td>\n" +
                "                      <td width=\"10%\"><a><img src=\"images/" + cha.photo + "\" alt=\"资格证号：111\" width=\"100\" height=\"100\" /></a></td>\n" +
                "                      <td><font color=\"#00CC99\">" + sex + "</font></td>\n" +
                "                      <td>" + cha.email + "</td>\n" +
                "                      <td>" + cha.phone + "</td>\n" +
                "                      <td><div class=\"button-group\"> <a class=\"button border-main\" href=\"pass.html\"  ><span class=\"icon-edit\"></span>重置密码</a> <a class=\"button border-red\" href=\"javascript:;\" onclick=\"return del(1,1,1)\"><span class=\"icon-trash-o\"></span>删除</a> </div></td>\n" +
                "                    </tr>")
        })
        $(".table").append(" <tr>\n" +
            "                <td colspan=\"9\"><div class=\"pagelist\"></div></td>\n" +
            "            </tr>")

        /*分页*/
        $(".pagelist").empty();
        if (data.pageNum > 1) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="1" >首页</a>')
        }
        if (data.pageNum - 1 >= 1) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + (data.pageNum - 1) + '" >上一页</a>')
        }
        $.each(data.navigatepageNums, function (index, fy) {
            if (data.pageNum == fy) {
                $(".pagelist").append(
                    "<a href=\"javascript:void(0)\" style='background-color: skyblue' class=\"curs\" id='" + fy + "'>" + fy + "</a>"
                )
            } else {
                $(".pagelist").append(
                    "<a href=\"javascript:void(0)\" class=\"curs\" id='" + fy + "'>" + fy + "</a>"
                )

            }

        })
        if (data.pageNum < data.pages) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + (data.pageNum + 1) + '" >下一页</a>')
        }
        if (data.pageNum < data.pages) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + data.pages + '" >末页</a>')
        }
        $(".curs").click(function () {
            $(".table").empty();
            tb();
            fy($(this).attr("id"), 3)
        })
    })
}